<%@ page import="com.hrm.entity.EmployeeEntity" %><%--
  Created by IntelliJ IDEA.
  User: zekdot
  Date: 20-3-10
  Time: 下午9:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <%--<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/table.css">--%>
    <link href="${pageContext.request.contextPath}/css/main.css" rel="stylesheet" type="text/css">
    <link href="${pageContext.request.contextPath}/bstable/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="${pageContext.request.contextPath}/bstable/css/bootstrap-table.css" rel="stylesheet" type="text/css">

    <script src="${pageContext.request.contextPath}/js/date/js/laydate.js"></script>
    <script src="${pageContext.request.contextPath}/bstable/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/bstable/js/bootstrap-table.js"></script>
    <script src="${pageContext.request.contextPath}/bstable/js/bootstrap-table-zh-CN.min.js"></script>
</head>
<body>
<%
    EmployeeEntity employeeEntity = (EmployeeEntity) session.getAttribute("user");
%>
    <div class="tabe_div">
        <p class="p_line text_ient"><a class="find_a">员工编号：</a>
            <input type="text" class="form_input text_ient" placeholder="输入编号" id="id"/>
            <input type="button" id="search" value="查看信息" class="but_find"/>
            <input type="button" value="添加员工" class="but_find"  onclick="openlayer('')"/>
        <p>
        <p class="p_table">
        </p>


        <table id="table" class="table_style" style="margin: 0 auto" >
        </table>
    </div>
    <script>
        $('#table').bootstrapTable({
            method:"get",
            striped: true,
            singleSelect: false,
            url:"${pageContext.request.contextPath}/employee/employees?dep=<%=employeeEntity.getDepartment()%>",
            dataType: "json",
            pagination: true, //分页
            pageSize: 10,
            pageNumber: 1,
            search: false, //显示搜索框
            contentType: "application/x-www-form-urlencoded",
            queryParams: null,
            columns: [
                {
                    title: "员工编号",
                    field: 'id',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '部门',
                    field: 'department',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '职位',
                    field: 'position',
                    align: 'center'
                },
                {
                    title: '在职情况',
                    field: 'status',
                    align: 'center',
                    formatter:function(value,row){
                        if(row.status == 0)
                            return '在职';
                        else
                            return '离职';
                    }
                },
                {
                    title: '操作',
                    field: 'oper',
                    align: 'center',
                    formatter: function (value, row) {


                        var e = '<button onclick="location.href=\'${pageContext.request.contextPath}/employee/editInfoPage?id=' + row.id + '\'">档案管理</button>';
                        var d = '<button onclick="location.href=\'${pageContext.request.contextPath}/employee/editSalaryPage?id=' + row.id + '\'">薪水管理</button>';
                        var c = '<button onclick="delEmp(\'' + row.id + '\')">删除员工</button>';
                        var b = '<button onclick="location.href=\'posPage?id=' + row.id + '\'">职位调动</button>'
                        return e + d + c + b;
                    }
                }
            ]
        });
        function isEId(str){
            if(str.length != 11)
                return false;
            if(str[0] != 'E'){
                return false;
            }
            for(var i=1;i<4;i++){
                if(str[i] <'a' || str[i] > 'z')
                    return false;
            }
            for(var i=4;i<11;i++){
                if(str[i] < '0' || str[i] > '9')
                    return false;
            }
            return true;
        }
        function delEmp(id){
            if(!confirm('您确定要删除id为' + id + '的员工？')){
                return;
            }
            var data = {'id':id};
            $.post('del',data,function (str) {
                var res = eval('(' + str + ')');
                if(res.code != 0) {
                    alert(res.message);
                    return;
                }
                alert('删除成功');
                $('#panel').html('');
            });
        }
        $('#search').click(function () {
            var id = $('#id').val();
            var data = {'id':id};
            $.post('${pageContext.request.contextPath}/employee/get',data,function(str){
                var res = eval('(' + str + ')');

                if(res.code != 0){
                    alert(res.message);
                    return;
                }
                res = res.object;
                if(res.department != '<%=employeeEntity.getDepartment()%>'){
                    alert('您不能查看其他部门员工的信息');
                    return;
                }
                var datas = [];
                datas.push(res);
                var setsData = {"data":datas};
                // console.log(JSON.stringify(setsData))
                $('#table').bootstrapTable('load',setsData);
            });

        });
        <%--$('#add').click(function(){--%>
            <%--var posList;--%>
            <%--$.get('${pageContext.request.contextPath}/department/pos?dep=<%=employeeEntity.getDepartment()%>',{},function(str){--%>
               <%--// alert(str)--%>
                <%--var res = eval('(' + str + ')');--%>
               <%--posList = res.object;--%>
                <%--var text1 = '<table>\n' +--%>
                    <%--'            <tr>\n' +--%>
                    <%--'                <td>\n' +--%>
                    <%--'                    员工编号:\n' +--%>
                    <%--'                </td>\n' +--%>
                    <%--'                <td>\n' +--%>
                    <%--'                    <input type="text" id="EId">\n' +--%>
                    <%--'                </td>\n' +--%>
                    <%--'            </tr>\n' +--%>
                    <%--'            <tr>\n' +--%>
                    <%--'                <td>\n' +--%>
                    <%--'                    职位:\n' +--%>
                    <%--'                </td>\n' +--%>
                    <%--'                <td>\n' +--%>
                    <%--'                    <select id="pos">\n';--%>

                <%--var text2 ='            </select>\n' +--%>
                    <%--'                </td>\n' +--%>
                    <%--'            </tr>\n' +--%>
                    <%--'            <tr>\n' +--%>
                    <%--'                <td colspan="2"><button id="sub">提交</button></td>\n' +--%>
                    <%--'            </tr>\n' +--%>
                    <%--'        </table>';--%>
                <%--for(var i=0;i<posList.length;i++){--%>
                    <%--text1 += '<option>' + posList[i] + '</option>'--%>
                <%--}--%>
                <%--text1 += text2;--%>
                <%--$('#panel').html(text1);--%>
                <%--$('#sub').click(function(){--%>
                   <%--var id = $('#EId').val(),pos = $('#pos').val();--%>
                   <%--// alert(id)--%>
                   <%--if(!isEId(id)){--%>
                       <%--alert('输入了非法的员工编号');--%>
                       <%--return ;--%>
                   <%--}--%>
                   <%--var data = {'id':id,'pos':pos};--%>
                   <%--$.post('add',data,function(str){--%>
                       <%--var res = eval('(' + str + ')');--%>
                       <%--if(res.code != 0){--%>
                           <%--alert(res.message);--%>
                       <%--}else{--%>
                           <%--alert('添加成功！');--%>
                           <%--$('#EId').val('');--%>
                       <%--}--%>
                   <%--});--%>
                <%--});--%>
            <%--});--%>
            // alert(posList)

        // });

    </script>

    <script src="${pageContext.request.contextPath}/layer_v2.1/layer/layer.js"></script>
    <script type="text/javascript">

        function openlayer(id){
            layer.open({
                type: 2,
                title: '添加信息',
                shadeClose: true,
                shade: 0.5,
                skin: 'layui-layer-rim',
               // maxmin: true,
                closeBtn:1,
                area: ['40%', '45%'],
                shadeClose: true,
                closeBtn: 1,
                content: '${pageContext.request.contextPath}/component/layer_box1.jsp'
                //iframe的url
            });
        }
    </script>
</body>
</html>
